<?php
declare (strict_types=1);

namespace app\callback\controller;

use app\BaseController;
use pay\WechatPay;
use Symfony\Component\HttpFoundation\Response;
use think\response\Json;
use wechat\WsOfficialAccount;
use wechat\WsOpenPlatform;
use wechat\WsWork;

/**
 * 微信回调Api
 */
class Wechat extends BaseController
{
    /**************************** 微信开放平台(平台服务商) ***********************/

    /**
     * 微信开放平台第三方平台授权
     * @return Response
     */
    public function wsThirdPartyAuthorize(): Response
    {
        $OpenPlatform = new WsOpenPlatform();
        return $OpenPlatform->verifyTicket();
    }

    /**
     * 微信开放平台第三方平台事件
     * @param string $appid
     * @return Response
     */
    public function wsThirdPartyEvent(string $appid): Response
    {
        //处理推送消息
        $OpenPlatform = new WsOpenPlatform();
        return $OpenPlatform->dealWithPushMsg($appid);
    }

    /**************************** 主体微信公众号 ********************************/
    /**
     * 无塑地球主体微信公众号验证token
     */
    public function getWsDistribution(): Response
    {
        $obj = new WsOfficialAccount();
        return $obj->wechatOfficialAccount();
    }

    /**
     * 无塑地球主体微信公众号接收事件
     * @return Response
     */
    public function postWsDistribution(): Response
    {
        $Ws = new WsOfficialAccount();
        return $Ws->automaticReply();
    }


    public function postWsWorkDistribution(): Response
    {
        $Ws = new WsWork();
        return $Ws->automaticReply();
    }

    /**************************** 微信支付回调 ********************************/

    /**
     * 微信支付回调
     * @return Json
     */
    public function wechatPayNoticeScanBag(): Json
    {
        $Ws = new WechatPay();
        return $Ws->wechatPayNotice('ScanBag');
    }
}
